/*
2021-7-15
https://www.acwing.com/problem/content/description/1060/
*/
#include<cstring>
#include<iostream>
#include<algorithm>

using namespace std;
const int N=1e5+5;
int n,w[N],f[N][3];

int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>w[i];
    
    f[0][0]=0,f[0][1]=f[0][2]=-0x3f3f3f3f;
    
    for(int i=1;i<=n;i++)
    {
        f[i][0]=max(f[i-1][0],f[i-1][2]);
        f[i][1]=max(f[i-1][1],f[i-1][0]-w[i]);
        f[i][2]=f[i-1][1]+w[i];
    }
    
    cout<<max(f[n][0],f[n][2])<<endl;
    
    return 0;
}
